<?php 
/**************************************************/
## Class Name - Model_COUNTRY (Contains all the functions related Country modules)
## Created By - Techmodi (22/08/2011)
/**************************************************/
class Model_Country extends Database
{	
	function Model_Country() {	
		$this->country = COUNTRY;		
		$this->Database();
	}
	
	// for add Country
	function addCountry($array) {
		$this->InsertData($this->country, $array);
	}
	
	## List all country
	function getAllCountry($search='',$col1='', $limit='', $offset='') {
		$fields = array();	
		$tables = array($this->country);		
		$where = array();
		if(trim($search)) {
			$where[] = "name_caps LIKE '%".$search."%' OR country_name LIKE '%".$search."%'";			
		}
		if($col1=='1')
			$order = $order = array("country_name DESC");
		else
			$order = array("country_name ASC");
		$result1 = $this->SelectData($fields,$tables, $where, $order, $group=array(),$limit,$offset,0); 
		$result  = $this->FetchAll($result1); 
		return $result;
	}
	
	## Get faq details by countryid
	function getCountryDetailsById($countryid) {
		$fields = array();	
		$tables = array($this->country);
		$result1 = $this->SelectData($fields,$tables, $where= array("country_id='".$countryid."'"), $order = array(), $group=array(),$limit = "",0,0); 
		$result  = $this->FetchRow($result1); 
		return $result;
	}
	
	## Edit Country by countryid
	function editCountryById($array, $countryid){
		$this->UpdateData($this->country,$array,"country_id",$countryid,0);
	}
	
	## Update Country status with multiple countryids
	function updateCountryStatus($countryid, $status) {		
		$sql = "UPDATE ".$this->country." SET country_status='".$status."' WHERE country_id = (".$countryid.")";
		$result1= $this->ExecuteQuery($sql);	 
		
	}
	
	## Delete country with multiple countryids
	function deleteCountry($countryids, $status) {
		$sql = "DELETE FROM ".$this->country." WHERE country_id IN (".$countryids.")";
		$result1= $this->ExecuteQuery($sql);	 
	}
	
	## Delete Country cat by id
	function deleteCountryById($countryid){
		$this->DeleteData($this->country,"country_id",$countryid);
	}
	
	/****************************************************/
	## Update country status with multiple countryids
	function updateMultipleCountryStatus($countryids, $status) {
		$sql = "UPDATE ".$this->country." SET country_status='".$status."' WHERE country_id IN (".$countryids.")";
		$result1= $this->ExecuteQuery($sql);	 
	}
	
	## Delete country category with multiple countryids
	function deleteMultipleCountry($countryids) {
		$sql = "DELETE FROM ".$this->country." WHERE country_id IN (".$countryids.")";
		$result1= $this->ExecuteQuery($sql);	 
	}
	
	## List all active country name
	function getAllCountryWithActiveStatus() {
		$fields = array('');	
		$tables = array($this->country);
		$where= array("country_status='1'");
		$result1 = $this->SelectData($fields,$tables, $where, $order = array(), $group=array(),$limit,$offset,0); 
		$result  = $this->FetchAll($result1); 
		return $result;
	}
	// Globle country name exist or not	
	function checkCountryName($countryname, $id='') {
		$fields=array();
		$tables=array($this->country);
		$where=array("name_caps='".$countryname."'");
		
		if($id != '') {
			$where[] = " country_id!=".$id;	
		}
		
		$result1 = $this->SelectData($fields,$tables, $where, $order = array(), $group=array(),$limit = "",0,0);
		$result= $this->FetchRow($result1);
		return $result;		
	}
	
}
?>


